home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / PInterfaces / MixedMode.p < prev    next >
Encoding:
Text File  |  1994-07-17  |  7.5 KB  |  294 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        MixedMode.p
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16.  
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT MixedMode;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __MIXEDMODE__}
  27. {$SETC __MIXEDMODE__ := 1}
  28.  
  29. {$I+}
  30. {$SETC MixedModeIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33.  
  34. {$IFC UNDEFINED __TYPES__}
  35. {$I Types.p}
  36. {$ENDC}
  37. {    ConditionalMacros.p                                            }
  38.  
  39. {$PUSH}
  40. {$ALIGN MAC68K}
  41. {$LibExport+}
  42.  
  43. CONST
  44.     kRoutineDescriptorVersion    = 7;
  45.  
  46. { MixedModeMagic Magic Cookie/Trap number }
  47.     _MixedModeMagic                = $AAFE;
  48.  
  49. { Calling Conventions }
  50.     
  51. TYPE
  52. CallingConventionType = INTEGER;
  53.  
  54.  
  55. CONST
  56.     kPascalStackBased            = 0;
  57.     kCStackBased                = 1;
  58.     kRegisterBased                = 2;
  59.     kD0DispatchedPascalStackBased = 8;
  60.     kD1DispatchedPascalStackBased = 12;
  61.     kD0DispatchedCStackBased    = 9;
  62.     kStackDispatchedPascalStackBased = 14;
  63.     kThinkCStackBased            = 5;
  64.  
  65. { ISA Types }
  66.     
  67. TYPE
  68. ISAType = SInt8;
  69.  
  70.  
  71. CONST
  72.     kM68kISA                    = 0;
  73.     kPowerPCISA                    = 1;
  74.  
  75. { RTA Types }
  76.     
  77. TYPE
  78. RTAType = SInt8;
  79.  
  80.  
  81. CONST
  82.     kOld68kRTA                    = 0+(0 * (2**(4)));
  83.     kPowerPCRTA                    = 0+(0 * (2**(4)));
  84.     kCFM68kRTA                    = 0+(1 * (2**(4)));
  85.  
  86. {$IFC GENERATINGPOWERPC }
  87.     GetCurrentISA                = kPowerPCISA;
  88.     GetCurrentRTA                = kPowerPCRTA;
  89.  
  90. {$ELSEC}
  91. {$IFC GENERATINGCFM }
  92.     GetCurrentISA                = kM68kISA;
  93.     GetCurrentRTA                = kCFM68kRTA;
  94.  
  95. {$ELSEC}
  96.     GetCurrentISA                = kM68kISA;
  97.     GetCurrentRTA                = kOld68kRTA;
  98.  
  99. {$ENDC}
  100. {$ENDC}
  101.     GetCurrentArchitecture        = 0+(GetCurrentISA + GetCurrentRTA);
  102.  
  103.     kRegisterD0                    = 0;
  104.     kRegisterD1                    = 1;
  105.     kRegisterD2                    = 2;
  106.     kRegisterD3                    = 3;
  107.     kRegisterD4                    = 8;
  108.     kRegisterD5                    = 9;
  109.     kRegisterD6                    = 10;
  110.     kRegisterD7                    = 11;
  111.     kRegisterA0                    = 4;
  112.     kRegisterA1                    = 5;
  113.     kRegisterA2                    = 6;
  114.     kRegisterA3                    = 7;
  115.     kRegisterA4                    = 12;
  116.     kRegisterA5                    = 13;
  117.     kRegisterA6                    = 14;
  118. { A7 is the same as the PowerPC SP }
  119.     kCCRegisterCBit                = 16;
  120.     kCCRegisterVBit                = 17;
  121.     kCCRegisterZBit                = 18;
  122.     kCCRegisterNBit                = 19;
  123.     kCCRegisterXBit                = 20;
  124.  
  125.     
  126. TYPE
  127. registerSelectorType = INTEGER;
  128.  
  129. { SizeCodes we use everywhere }
  130.  
  131. CONST
  132.     kNoByteCode                    = 0;
  133.     kOneByteCode                = 1;
  134.     kTwoByteCode                = 2;
  135.     kFourByteCode                = 3;
  136.  
  137. { Mixed Mode Routine Records }
  138.     
  139. TYPE
  140. ProcInfoType = LONGINT;
  141.  
  142. { Routine Flag Bits }
  143.     RoutineFlagsType = INTEGER;
  144.  
  145.  
  146. CONST
  147.     kProcDescriptorIsAbsolute    = $00;
  148.     kProcDescriptorIsRelative    = $01;
  149.  
  150.     kFragmentIsPrepared            = $00;
  151.     kFragmentNeedsPreparing        = $02;
  152.  
  153.     kUseCurrentISA                = $00;
  154.     kUseNativeISA                = $04;
  155.  
  156.     kPassSelector                = $0;
  157.     kDontPassSelector            = $08;
  158.  
  159.     kRoutineIsNotDispatchedDefaultRoutine = $0;
  160.     kRoutineIsDispatchedDefaultRoutine = $10;
  161.  
  162.  
  163. TYPE
  164.     RoutineRecord = RECORD
  165.         procInfo:                ProcInfoType;                            { calling conventions }
  166.         reserved1:                SInt8;                                    { Must be 0 }
  167.         ISA:                    ISAType;                                { Instruction Set Architecture }
  168.         routineFlags:            RoutineFlagsType;                        { Flags for each routine }
  169.         procDescriptor:            ProcPtr;                                { Where is the thing we’re calling? }
  170.         reserved2:                LONGINT;                                { Must be 0 }
  171.         selector:                LONGINT;                                { For dispatched routines, the selector }
  172.     END;
  173.     RoutineRecordPtr = ^RoutineRecord;
  174.     RoutineRecordHandle = ^RoutineRecordPtr;
  175.  
  176. { Mixed Mode Routine Descriptors }
  177. { Definitions of the Routine Descriptor Flag Bits }
  178.     RDFlagsType = UInt8;
  179.  
  180.  
  181. CONST
  182.     kSelectorsAreNotIndexable    = $00;
  183.     kSelectorsAreIndexable        = $01;
  184.  
  185. { Routine Descriptor Structure }
  186.  
  187. TYPE
  188.     RoutineDescriptor = PACKED RECORD
  189.         goMixedModeTrap:        INTEGER;                                { Our A-Trap }
  190.         version:                SInt8;                                    { Current Routine Descriptor version }
  191.         routineDescriptorFlags:    RDFlagsType;                            { Routine Descriptor Flags }
  192.         reserved1:                LONGINT;                                { Unused, must be zero }
  193.         reserved2:                UInt8;                                    { Unused, must be zero }
  194.         selectorInfo:            UInt8;                                    { If a dispatched routine, calling convention, else 0 }
  195.         routineCount:            INTEGER;                                { Number of routines in this RD }
  196.         routineRecords:            ARRAY [0..0] OF RoutineRecord;            { The individual routines }
  197.     END;
  198.     RoutineDescriptorPtr = ^RoutineDescriptor;
  199.     RoutineDescriptorHandle = ^RoutineDescriptorPtr;
  200.  
  201.  
  202. CONST
  203. { Calling Convention Offsets }
  204.     kCallingConventionWidth        = 4;
  205.     kCallingConventionPhase        = 0;
  206. { Result Offsets }
  207.     kResultSizeWidth            = 2;
  208.     kResultSizePhase            = kCallingConventionWidth;
  209.     kResultSizeMask                = $30;
  210. { Parameter offsets & widths }
  211.     kStackParameterWidth        = 2;
  212.     kStackParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth);
  213. { Register Result Location offsets & widths }
  214.     kRegisterResultLocationWidth = 5;
  215.     kRegisterResultLocationPhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  216. { Register Parameter offsets & widths }
  217.     kRegisterParameterWidth        = 5;
  218.     kRegisterParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth);
  219.     kRegisterParameterSizePhase    = 0;
  220.     kRegisterParameterWhichPhase = 2;
  221. { Dispatched Stack Routine Selector offsets & widths }
  222.     kDispatchedSelectorSizeWidth = 2;
  223.     kDispatchedSelectorSizePhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  224. { Dispatched Stack Routine Parameter offsets }
  225.     kDispatchedParameterPhase    = 0+(kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth);
  226. { Special Case offsets & widths }
  227.     kSpecialCaseSelectorWidth    = 6;
  228. { Component Manager Special Case offsets & widths }
  229.     kComponentMgrResultSizeWidth = 2;
  230.     kComponentMgrResultSizePhase = kCallingConventionWidth + kSpecialCaseSelectorWidth; { 4 + 6 = 10 }
  231.     kComponentMgrParameterWidth    = 2;
  232.     kComponentMgrParameterPhase    = kComponentMgrResultSizePhase + kComponentMgrResultSizeWidth; { 10 + 2 = 12 }
  233.  
  234.     kSpecialCase                = $0000000F;
  235.  
  236. { all of the special cases enumerated.  The selector field is 6 bits wide }
  237.     kSpecialCaseHighHook        = 0;
  238.     kSpecialCaseCaretHook        = 0;                            { same as kSpecialCaseHighHook }
  239.     kSpecialCaseEOLHook            = 1;
  240.     kSpecialCaseWidthHook        = 2;
  241.     kSpecialCaseTextWidthHook    = 2;                            { same as kSpecialCaseWidthHook }
  242.     kSpecialCaseNWidthHook        = 3;
  243.     kSpecialCaseDrawHook        = 4;
  244.     kSpecialCaseHitTestHook        = 5;
  245.     kSpecialCaseTEFindWord        = 6;
  246.     kSpecialCaseProtocolHandler    = 7;
  247.     kSpecialCaseSocketListener    = 8;
  248.     kSpecialCaseTERecalc        = 9;
  249.     kSpecialCaseTEDoText        = 10;
  250.     kSpecialCaseGNEFilterProc    = 11;
  251.     kSpecialCaseMBarHook        = 12;
  252.     kSpecialCaseComponentMgr    = 13;
  253.  
  254. {$IFC GENERATINGCFM }
  255.  
  256. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ByteParameter): UniversalProcPtr;
  257.     {$IFC NOT GENERATINGCFM}
  258.     INLINE $7000, $AA59;
  259.     {$ENDC}
  260. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  261.     {$IFC NOT GENERATINGCFM}
  262.     INLINE $7001, $AA59;
  263.     {$ENDC}
  264. FUNCTION NewFatRoutineDescriptor(theM68kProc: ProcPtr; thePowerPCProc: ProcPtr; theProcInfo: ProcInfoType): UniversalProcPtr;
  265.     {$IFC NOT GENERATINGCFM}
  266.     INLINE $7002, $AA59;
  267.     {$ENDC}
  268. {$ELSEC}
  269.  
  270. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ByteParameter): UniversalProcPtr;
  271.     {$IFC NOT GENERATINGCFM}
  272.     INLINE $5C4F, $2E9F;
  273.     {$ENDC}
  274. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  275.     {$IFC NOT GENERATINGCFM}
  276.     INLINE $584F;
  277.     {$ENDC}
  278. {$ENDC}
  279. {$IFC GENERATINGPOWERPC }
  280. FUNCTION CallUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  281. FUNCTION CallOSTrapUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  282. {$ENDC}
  283.  
  284. {$ALIGN RESET}
  285. {$POP}
  286.  
  287. {$SETC UsingIncludes := MixedModeIncludes}
  288.  
  289. {$ENDC} {__MIXEDMODE__}
  290.  
  291. {$IFC NOT UsingIncludes}
  292.  END.
  293. {$ENDC}
  294.